import './assets/main.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import vue3LockScreen from 'vue3-lock-screen' // 引入组件
import 'vue3-lock-screen/dist/style.css' // 引入组件样式
import axios from 'axios'

const app = createApp(App)

// 全局属性
app.config.globalProperties.$axios = axios
app.config.globalProperties.$apiBaseUrl = 'http://localhost:8088'

app.use(vue3LockScreen) // 全局注册
app.use(router)
app.use(ElementPlus)

// 路由守卫
router.beforeEach((to, from, next) => {
	let token = window.sessionStorage.getItem('loginState');
	if (to.path !== '/login' && to.path !== '/forget' && (token === null || token === 'false')) {
		window.sessionStorage.setItem('loginState', false);
		next({ path: '/login' });
	} else {
		next();
	}
});

app.mount('#app')
